<template>
    <div>
        <table>
            <tbody>
                <tr>
                    <td>用户名</td>
                    <td>
                        <input type="text" v-model="info.username">
                    </td>
                </tr>
                <tr>
                    <td>密码</td>
                    <td>
                        <input type="password" v-model="info.password">
                    </td>
                </tr>
                <tr>
                    <td></td>
                    <td>
                        <input type="button" value="登录" @click="login">
                    </td>
                </tr>
            </tbody>
        </table>
    </div>
</template>

<script setup lang="ts">
import axios from 'axios';
import { ref } from 'vue';
import { useRouter } from 'vue-router';

const router = useRouter();

const info=ref({
    username:"",
    password:"",
})

const login=()=>{
    if(info.value.username==""){
        alert("用户名不能为空");
        return;
    }
    if(info.value.password==""){
        alert("密码不能为空");
        return;
    }
    axios.get("https://localhost:7168/api/User/Login",{params:info.value}).then((res)=>{
        if(res.data.Uid>0){
            alert("登录成功");
            router.push("/Add");
        }
        else{
            alert("登录失败");
        }
    })
}



</script>

<style scoped>

</style>